﻿using MainFrameDesign.Component;
using MainFrameDesign.ContentContorl;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml;
using MainInterface;
namespace MainFrmTool.ToolBox
{
     public class ToolBoxItem
    {
        public string Text = string.Empty;
        public string TypeName = string.Empty;
        public Image ToolImg = null;
        internal bool IsHover = false;
        internal bool IsSelect = false;
        internal Rectangle DrawRect = new Rectangle(0, 0, 200, 20);
        internal Rectangle DrawText = new Rectangle(20, 0, 180, 20);
        public Div ItemControl { get; set; }
        public ToolBoxItem()
        {
             
        }

        public virtual void Draw(Graphics g,ref int Y,int width) 
        {
            DrawRect.Width = width;
            DrawText.Width = width - 20;
            DrawRect.Y = Y;
            DrawText.Y = Y;
            Y += DrawRect.Height;
            if (IsSelect) 
            {
                g.FillRectangle(ToolBoxDraw.SelectBrush, DrawRect);
                g.DrawString(this.Text, SystemFonts.CaptionFont, Brushes.White, DrawText, ToolBoxDraw.TextAlign);
            }
            else if (IsHover)
            {
                g.FillRectangle(Brushes.White, DrawRect);
                g.DrawString(this.Text, SystemFonts.CaptionFont, Brushes.Black, DrawText, ToolBoxDraw.TextAlign);
            }
            else 
            {
                g.DrawString(this.Text, SystemFonts.CaptionFont, Brushes.Black, DrawText, ToolBoxDraw.TextAlign);
            }
            if (ToolImg != null)
            {
                g.DrawImage(ToolImg, 4, DrawRect.Y + 4, 12, 12);  
            }
            else 
            {
                g.DrawImage(ToolBoxDraw.NormalImg, 4, DrawRect.Y + 4, 12, 12); 
            } 
        }

        public Div CreateNew(string name)
        {
            Div tem = null;
            if (this.TypeName == "Div") 
            {
                tem = new Div();
            }
            else if (this.TypeName == "SplitLR")
            {
                tem = new SplitLR();
            }
            else 
            {
                MyComponent comm = this.ItemControl as MyComponent;
                tem = comm.Copy();
            }
            tem.Name = name;
            return tem;
        }
    }
}
